from odoo import fields,models,api


class PeSoftwareAssets(models.Model):
    _name = 'pe.software.assets'
    _inherit = ["mail.thread", "mail.activity.mixin"]
    _description = '软件产品'
    _rec_name = 'sale_name'
    _sql_constraints = [('unique_internal_code','UNIQUE(internal_code)','内部编码需要唯一！')]


    sale_model=fields.Char(string='销售型号',tracking=True)
    sale_name=fields.Char(string='销售名称',translate=True,tracking=True)
    internal_code=fields.Char(string='内部编码',tracking=True)
    internal_name=fields.Char(string='内部名称',tracking=True)

    pe_product_line_id=fields.Many2one(string='产品线',comodel_name='pe.product.line',tracking=True)
    pe_business_category_id=fields.Many2one(string='业务分类',comodel_name='pe.business.category',tracking=True)
    pe_service_category_ids=fields.Many2many(string='服务类型',comodel_name='pe.service.category',column1='pe_software_assets_id',
                                             column2='pe_service_category_id',tracking=True)

    remark=fields.Char(string='备注',tracking=True)


    @api.model_create_single
    def create(self, vals):
        vals['code']=self.env['ir.sequence'].next_by_code('pe.software.assets') or '/'
        return super(PeSoftwareAssets, self).create(vals)


